function uploadFiles(files, flag) {
	uploadFile(files, flag, "/bd/factory/upload_img.htm", null, null);
};

function modifyFiles(files, fileType, factoryId) {
	uploadFile(files, fileType, "/bd/factory/modify_upload_img.htm", factoryId);
};

function uploadFile(files, flag, url, factoryId) {
		if($("#" + files).val().length > 0) {
			var index = $("#" + files).val().lastIndexOf(".") + 1;
			var suffix = $("#" + files).val().substring(index, $("#" + files).val().length);
			if(suffix.toLowerCase() == "png" || suffix.toLowerCase() == "jpg" || suffix.toLowerCase() == "jpeg") {
				$.ajaxFileUpload({
					url: url,
					secureuri: false,
					data: {
						"steelFactoryId": factoryId,
						"fileType": flag
					},
					fileElementId: files, // file标签的id
					success: function(file) {
						if(file != "" && typeof file != undefined) {
							var data = file;
							var uploadStatus = data.actionStatus;
							if(uploadStatus == 'success') {
								var message = eval("(" + data.actionMessage + ")");

								$.each(message, function(i, f) {
									if(f.error == "1") {
										bootbox.dialog({
											title: '<span class="vmiddle">提示<span>',
											message: "<p>图片:" + f.message + "</p>",
											className: "bootbox-small-style1",
											buttons: {
												success: {
													label: "确定",
													className: "btn-blue",
													callback: function() {}
												}
											}
										});

										return;
									}

									var div0 = $('<div class="col-sm-3 picbox"></div>');
									var div1 = $('<div class="form-group"></div>');
									var div2 = $('<div class="rela"></div>');
									var inputName = $('<input type="hidden" name="img' + flag + 'Name" value="' + f.fileName + '">')
									var inputUrl = $('<input type="hidden" name="img' + flag + 'Url" value="' + f.url + '">')
									var imgPut = $('<img class="up-img viewer-toggle" src="http://mfs.banksteel.com/' + f.url + '" height="157" width="196">');
									var stringurl = "'" + f.url + "'";
									var newSpan = $('<span class="del" id=' + f.id + ' onclick="deleteImg(' + stringurl + ',this)"></span>');
									div2.append(imgPut).append(inputUrl).append(inputName);
									div2.append(newSpan);
									div1.append(div2);
									div0.append(div1);
									$("#img" + flag).append(div0);
									 $(".dlList img").viewer();
								});
							}
						} else {
							alert("上传失败");
							return false;
						}
					}
				});
			} else {
				$("#imgspan" + flag).text(
					"请选择.png 和.jpg及.jpeg格式的图片上传!")
				document.getElementById("imgspan" + flag).style.display = "block";
				return false;
			}
		}
}

function upload(uploadFile) {
	$("#" + uploadFile)
		.change(
			function() {
				if($("#" + uploadFile).val().length > 0) {
					var index = $("#" + uploadFile).val().lastIndexOf(
						".") + 1;
					var suffix = $("#" + uploadFile).val().substring(
						index, $("#" + uploadFile).val().length);
					if(suffix.toLowerCase() == "png" ||
						suffix.toLowerCase() == "jpg" ||
						suffix.toLowerCase() == "jpeg") {
						$
							.ajaxFileUpload({
								url: "/pop/file/upload_img.htm",
								secureuri: false,
								fileElementId: "uploadFile", // file标签的id
								success: function(file) {
									if(file != "" &&
										typeof file != undefined) {
										var data = file;

										var uploadStatus = data.actionStatus;
										if(uploadStatus == 'success') {
											var message = eval("(" +
												data.actionMessage +
												")")

											var url = message.url;

											$("#fileName")
												.val(
													message.fileName);

											$("#fileUrl").val(url);

											document
												.getElementById("imgId").src = "http://mfs.banksteel.com/" +
												url;
											document
												.getElementById('imgId').style.display = "block";
											$("#imgspan").hide();
										} else {
											var mesg = data.actionMessage;
											$("#imgspan")
												.text(mesg);
											document
												.getElementById("imgspan").style.display = "block";
											return false;
										}
									} else {
										alert("上传失败");
										return false;
									}
								}
							});
					} else {
						$("#imgspan").text(
							"请选择.png 和.jpg及.jpeg格式的图片上传!")
						document.getElementById("imgspan").style.display = "block";
						return false;
					}
				}

			})
}